﻿namespace NTLib.Pipe.Containers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// Two way implementation of the PipeOwner
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal sealed class TwoWayPipeOwner<T> : TwoWayPipe<T>, IPipeManipulatorOwner<T>
    {
        #region Methods

        /// <summary>
        /// Closes the pipe.
        /// </summary>
        public async Task ClosePipeAsync()
        {
            IPipeOwner owner = base.Source as IPipeOwner;

            if (owner != null)
                await owner.ClosePipeAsync();
        }

        #endregion
    }

    /// <summary>
    /// Push only way implementation of the PipeOwner
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal sealed class PushOnlyPipeOwner<T> : PushOnlyPipe<T>, IPipeManipulatorOwner<T>
    {
        #region Methods

        /// <summary>
        /// Closes the pipe.
        /// </summary>
        public async Task ClosePipeAsync()
        {
            IPipeOwner owner = base.Source as IPipeOwner;

            if (owner != null)
                await owner.ClosePipeAsync();
        }

        #endregion
    }
    /// <summary>
    /// Read only way implementation of the PipeOwner
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal sealed class ReadOnlyPipeOwner<T> : ReadOnlyPipe<T>, IPipeManipulatorOwner<T>
    {
        #region Methods

        /// <summary>
        /// Closes the pipe.
        /// </summary>
        public async Task ClosePipeAsync()
        {
            IPipeOwner owner = base.Source as IPipeOwner;

            if (owner != null)
                await owner.ClosePipeAsync();
        }

        #endregion
    }
}
